package com.shanling.shanlingcontroller.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.shanling.shanlingcontroller.persenter.BasePersenter;
import com.shanling.shanlingcontroller.ui.BaseView;


/**
 * Created by sinrow on 2019/2/12 0016.
 */

public abstract class BaseMVPActivity<T extends BasePersenter> extends BaseAppCompatActivity implements BaseView {

    protected T mPersenter;

    @Override
    @SuppressWarnings("unchecked")
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (mPersenter == null) {
            mPersenter = createPresenter();
        }
        mPersenter.attachView(this);
        super.onCreate(savedInstanceState);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPersenter.detachView();
    }

    protected abstract T createPresenter();

}
